package com.hibernate.home.oneTOone.program;

import java.util.Date;

import javax.transaction.Transaction;

import org.hibernate.HibernateError;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.hibernate.home.oneTOone.model.entity.Employee;
import com.hibernate.home.oneTOone.model.entity.EmployeeDetail;
import com.hibernate.home.oneTOone.model.util.HibernateUtil;

public class Drive {

	public static void main(String[] args) {

		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		org.hibernate.Transaction transaction = session.beginTransaction();
		try {
			Employee employee = new Employee();
			EmployeeDetail employeeDetail = new EmployeeDetail();
			employee.setFirstname("Masal");
			employee.setLastname("karaman");
			employee.setSalary(50000d);
			employee.setHiredate(new Date());
			employeeDetail.setEmail("masal@");
			employeeDetail.setDeparment("IT");
			employeeDetail.setLogintime(new Date());
			employee.setEmployeeDetail(employeeDetail);
			session.save(employee);
		} catch (HibernateError e) {
			e.printStackTrace();

		} finally {
			transaction.commit();
			session.close();
			sessionFactory.close();
		}
	}

}
